package com.dhj.jvmstudy.chapter07;

/**
 * String的基本使用，体现String的不可变性
 */
public class StringTest1 {

    public static void main(String[] args) {
        test1();
        test2();
        test3();
    }


    public static void test1() {
        String s1 = "abc";  // 字面量定义的方法，“abc”存储在字符串常量池中
        String s2 = "abc";
        s1 = "hello";

        System.out.println(s1 == s2);   // 判断地址：true --> false
        System.out.println(s1);
        System.out.println(s2);
    }

    public static void test2() {
        String s1 = "abc";
        String s2 = "abc";
        s1 += "def";

        System.out.println(s1);
        System.out.println(s2);
    }

    public static void test3() {
        String s1 = "abc";
        String s2 = "abc".replace('a', 'm');

        System.out.println(s1);
        System.out.println(s2);
    }

}
